<template>
  <div>
    <el-row style="margin-bottom: 20px;margin-top: -10px" :gutter="10">
      <el-col :span="6">
        <el-card style="color: #409EFF">
          <div><i class="el-icon-user"></i> 用户总数</div>
          <div style="padding: 10px 0;text-align: center " font-size="20px">{{ count }}</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #F56C6C">
          <div><i class="el-icon-goods"></i> 销售总量</div>
          <div style="padding: 10px 0;text-align: center " font-size="20px">100</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #67C23A">
          <div><i class="el-icon-bank-card"></i> 收益总额</div>
          <div style="padding: 10px 0;text-align: center " font-size="20px">100</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #E6A23C">
          <div><i class="el-icon-s-shop"></i> 门店总数</div>
          <div style="padding: 10px 0;text-align: center " font-size="20px">100</div>
        </el-card>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="12">
        <div style="width: 500px;height: 450px" id="main"></div>
      </el-col>
      <el-col :span="12">
        <div style="width: 500px;height: 450px" id="pie"></div>
      </el-col>
    </el-row>
  </div>

</template>

<script>
import * as echarts from 'echarts';

export default {
  data() {
    return {
        count:0
      }
    },
  mounted() {
    // 条形图+折线图
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    var optionchar = {
      title: {
        text: '会员季度统计表',
        left: 'center'
      },
      xAxis: {
        type: 'category',
        data: ['第一季度', '第二季度', '第三季度', '第四季度']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'line',
        },
        {
          data: [],
          type: 'bar',
        }
      ]
    };

    // 饼图
    var pieDom = document.getElementById('pie');
    var mypie = echarts.init(pieDom);
    var optionPie = {
      title: {
        text: '会员季度统计饼图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item',
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },

      series: [
        {
          type: 'pie',
          radius: '60%',
          data: [],
          label: {
            normal: {
              show: true,
              position: "inner",
              textStyle: {
                fontWeight: 200,
                fontSize: 15, //文字的字体大小
              },
              formatter: "{d}%", /*饼状图内显示百分比*/
              color: "#fff",
            },
          },
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };
    // 请求数据
    this.request.get("/user/count").then(res => {
      if (res.code == 200) {
        this.count=res.data[0]+res.data[1]+res.data[2]+res.data[3] // 总数
        optionchar.series[0].data = res.data
        optionchar.series[1].data = res.data
        optionPie.series[0].data = [
          {value: res.data[0], name: '第一季度'},
          {value: res.data[1], name: '第二季度'},
          {value: res.data[2], name: '第三季度'},
          {value: res.data[3], name: '第四季度'}
        ]
        myChart.setOption(optionchar);
        mypie.setOption(optionPie);
      }
    })

  },

}
</script>


<style scoped>

</style>